'OHRRPGCE CUSTOM - Original Main module
'(C) Copyright 1997-2005 James Paige and Hamster Republic Productions
'Monkey Port by Landon Ritchie

'Strict

Import diddy
Import angelfont
Import screens
Import udts
Import drawing
Import globals

Function Main:Int()
	New MyGame()
	Return 0
End


'add palettes
'set default text strings

'breaking up editor menu into categories Graphics,Data,Audio


Class MyGame Extends DiddyApp
	Method Create:Void()
		SetScreenSize(640, 480)
		drawFPSOn = True
		Print "Screen: "+SCREEN_WIDTH
		LoadImages()	
		CreateDefaultMedia()
		CreateMenus()
		'MAIN SCREEN TURN ON
		Start(titleScreen)
	End

	Method CreateDefaultMedia()
	
		CreatePalette()
		CreateWalkabout()
		CreateFont()
		CreateTileset()
		CreateTilemaps()
	End	
	
	Method CreateTileset()

		'clean this and shove it into some universal function
		Local tm:HTileMapTileset[1]
		tm[0] = New HTileMapTileset
		tm[0].name = "Default"
		tm[0].tileWidth = 32
		tm[0].tileHeight = 32	
		tm[0].edsprites = New SpriteSet
		tm[0].edsprites.SetFrames(160,32,32,"tileset_ed_sprites"+Rnd+"_")	
		Local hi:HGameImage = New HGameImage
		Local hib:HGameImage = New HGameImage
		Local tmp:Image = CreateImage(512,320)
		'create anim image
		Local anim:Image = tmp.GrabImage( 0,0,32,32,160,0)
		hi.HLoad(anim,tm[0].name,True,True,0,0,0,False)
		hib.HLoad(tmp,tm[0].name,True,True,0,0,0,False)
	
		tm[0].simage = hib
		tm[0].image = GameImage(hi)
		tm[0].image.frames = 160
		tm[0].image.w = 32
		tm[0].image.h = 32
		
		tm[0].simage.tileWidth = 32
		tm[0].simage.tileHeight = 32
		tm[0].simage.tileCountX = 16
		tm[0].simage.tileCountY = 10
		tm[0].simage.tileCount = 160
		tm[0].simage.tileSpacing = 0
		tm[0].simage.tileMargin = 0			
		
		'tm[0].simage.tileCount = 160
		Local tmt:TileMapTile[160]
		For Local i:Int = 0 To 159
			tmt[i] = New TileMapTile(i)
			tmt[i].image = tm[0].simage
			tmt[i].width = 32
			tmt[i].height = 32
			tmt[i].gid = i+1					
		Next
		tm[0].tiles = tmt
		tm[0].PostLoad()
		TileSets = tm
		
	End
	
	Method CreateTilemaps()
	
		Local tm:HTileMap[1]
		tm[0] = New HTileMap
		tm[0].tname = "Default Map "+Int(Rnd())
		tm[0].tilesets.Set(TileSets[0].name, TileSets[0])
		tm[0].width = 64
		tm[0].height = 64
		tm[0].tileWidth = 32
		tm[0].tileHeight = 32
		tm[0].maxTileWidth = tm[0].tileWidth
		tm[0].maxTileHeight = tm[0].tileHeight	
		tm[0].tiles = TileSets[0].tiles
		'create base layer	
		Local rv:TileMapTileLayer = tm[0].CreateTileLayer()
		rv.width = tm[0].width
		rv.height = tm[0].height
		tm[0].layers.Add(rv)
		Local tv:TileMapData = tm[0].CreateData(rv.width, rv.height)
		For Local i:Int = 0 To (rv.width*rv.height)-1
			tv.tiles[i] = 1
			tv.cells[i] = tm[0].CreateCell(1, i Mod tv.width, i / tv.width)
		next
		rv.mapData = tv
		'tm[0].CalcSize()
		Tilemaps = tm
			
	End
	
	Method CreateFont()
	
		MainFont = New AngelFont()
		MainFont.LoadFontXml(diddyGame.images.path + "knight")
	End
	
	Method CreatePalette()
		Local p:Palette256[1]
		
		p[0] = New Palette256
		p[0].DefaultPalette()
		Palettes = p
	
	end
	
	Method CreateWalkabout()
	
		Local sprset:SpriteSet[1]
		sprset[0] = New SpriteSet
		sprset[0].SetFrames(8,32,48,"Default_")
		'sprset[1] = New SpriteSet
		'sprset[1].SetFrames(8,32,48,"Default2_")		
		WalkaboutSpr = sprset
	
	End
	
	Method CreateMenus()
	
		titleScreen = New TitleScreen
		gameScreen = New GameScreen
		optionScreen = New OptionScreen
		mainedscreen = New MainEditorScreen
		gfxscreen = New GraphicsScreen
		heronenemy = New HeronEnemyScreen
		walkabout = New WalkaboutScreen	
		maptiles = New MaptilesScreen
		datas = New DataScreen
	End
	'***********************
	'* Load Images
	'***********************
	Method LoadImages:Void()
		'images.Load("splash.png")
		MainLogo = LoadImage(diddyGame.images.path + "logo.png")
	End	
	
End





